<template>
  <div class="zw_mian">
    <div class="titel_text">展位信息确认</div>
    <div class="zw_input_warp">
      <el-form
        inline
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="140px"
        class="demo-ruleForm"
      >
        <el-form-item label="展位层数类型:" prop="standLevelType">
          <el-select
            @select="select"
            v-model="ruleForm.standLevelType"
            placeholder="请选择"
          >
            <el-option
              v-for="dict in dict.type.stand_level_type"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="展位位置类型:" prop="standPosType">
          <el-select v-model="ruleForm.standPosType" placeholder="请选择">
            <el-option
              v-for="item in dict.type.stand_pos_type"
              :key="item.value"
              :label="item.label"
              :value="parseInt(item.value)"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="展位材质类型:" prop="standTexture">
          <el-select v-model="ruleForm.standTexture" placeholder="请选择">
            <el-option
              v-for="item in dict.type.stand_texture"
              :key="item.value"
              :label="item.label"
              :value="parseInt(item.value)"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="展台高度:" prop="standHeight">
          <el-input type="number" v-model="ruleForm.standHeight"></el-input>
        </el-form-item>
        <el-form-item label="是否吊点:" prop="isLiftingpoint">
          <el-select v-model="ruleForm.isLiftingpoint" placeholder="请选择">
            <el-option
              v-for="item in dict.type.sys_number_yes_no"
              :key="item.value"
              :label="item.label"
              :value="parseInt(item.value)"
            >
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
    </div>
    <div class="but_warp">
      <el-button size="mini" @click="hanldnext(0)">上一步</el-button>
      <el-button size="mini" @click="hanldaddexhibition" type="danger"
        >保存并下一步</el-button
      >
    </div>
  </div>
</template>
<script>
import { stand_info, zwapply, upalodapply, genarateCadAttachment, getStandInfo } from "@/api/outfit/drawingadd.js";
import { getToken, setToken } from "@/utils/auth";
export default {
  name: 'step2',
  dicts: [
    "stand_level_type",
    "stand_texture",
    "stand_pos_type",
    "sys_number_yes_no",
  ],
  data() {
    return {
      ruleForm: {},
      jDdata: {},
      rules: {
        standLevelType: [
          { required: true, message: "请选择展位层数类型", trigger: "change" },
        ],
        standPosType: [
          { required: true, message: "请选择展位位置类型", trigger: "change" },
        ],
        standTexture: [
          { required: true, message: "请选择展位材质类型", trigger: "change" },
        ],
        standHeight: [
          { required: true, message: "请输入展台高度", trigger: "blur" },
        ],
        isLiftingpoint: [
          { required: true, message: "请选择是否吊点", trigger: "change" },
        ],
        standArea: [
          { required: true, message: "请输入展台面积", trigger: "blur" },
        ],
      },
    };
  },
  activated() {
    this.jDdata = JSON.parse(getToken("jd"));

    console.log(this.jDdata);
    if (this.jDdata) {
      this.ruleForm = this.jDdata.exhibitioinStandInfo;
    }
  },
  created() {
    this.jDdata = JSON.parse(getToken("jd"));
    if (this.jDdata) {
      this.ruleForm = this.jDdata.exhibitioinStandInfo;
      console.log(this.ruleForm)
    }
  },
  methods: {
    select(val) {
      console.log(val);
    },
    hanldnext(index) {
      this.$emit("hanldnext", index);
    },
    hanldaddexhibition() {
      let exhibitiondata = JSON.parse(getToken("exhibition"));
      console.log('stanId',getToken('stanId'));
      let stanId = getToken("stanId");
      if (!stanId) {
        return this.$message.error("请返回上一步选择展位");
      }
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          // if (this.jDdata) {
          //   console.log("12");
          //   this.ruleForm.standOwner =
          //     this.jDdata.exhibitioinStandInfo.standOwner;
          //   this.ruleForm.standOwnerTel =
          //     this.jDdata.exhibitioinStandInfo.standOwnerTel;
          //   this.ruleForm.exProducerId =
          //     this.jDdata.exhibitioinStandInfo.exProducerId;
          // }
          // //this.ruleForm.exhibitionCompany = exhibitiondata.exhibitionCompany;
          this.ruleForm.exProduceId = exhibitiondata.exhibitionName.id;
          this.ruleForm.id = stanId;
          getStandInfo(stanId).then((res) => {
            let stan = res.data;
            if (res.code == 200) {
              stand_info(this.ruleForm).then((res) => {
                if (res.code == 200) {
                  console.log("res",res)
                  let username = getToken("username");
                  // setToken("stan", JSON.stringify(res.data));
                  //console.log("type", typeof(res.data.isLiftingpoint))
                  let formdata = {
                    constructionName: username,
                    exhibition: exhibitiondata.exhibitionName,
                    standId: stanId,
                    standNum: stan.standNum,
                    standArea: this.ruleForm.standArea,
                    applyStatus: 4,
                    applyPerson: username,
                    exNumber: stan.exNumber,
                    applyStep: 2,
                  };
                  if (!this.jDdata) {
                    zwapply(formdata).then((res) => {
                      genarateCadAttachment(res.data.id);
                      console.log(res);
                      setToken("applyid", res.data.id);
                      if (res.code == 200) {
                        this.hanldnext(2);
                      }
                    });
                  }else{
                    this.hanldnext(2);
                  }
                }
              });
            }
          })
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
  },
};
</script>
<style scoped>
.titel_text {
  padding: 15px;
  font-size: 20px;
  font-weight: bold;
  border-bottom: 1px solid #e0e2e6;
}
.zw_input_warp {
  margin: 20px 0;
}
.but_warp {
  padding: 20px;
  display: flex;
  justify-content: flex-end;
}
</style>